package org.yookiee.support.enums;

import com.google.common.base.Strings;

/**
 * company -
 * FileName DatePatternEnum
 * Package org.yookiee.support.enums
 * Description format template enum
 * author cpstory
 * create 2023-11-23 8:58
 * version V1.0
 */
public enum DatePatternEnum {


    YMD_HMS("yyyy-MM-dd HH:mm:ss","^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) (0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$"),
    YMD_HM("yyyy-MM-dd HH:mm","^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) (0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])$"),
    YMD("yyyy-MM-dd","^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$")
    ;

    private String pattern;
    private String reg;

    DatePatternEnum(String pattern, String reg) {
        this.pattern = pattern;
        this.reg = reg;
    }

    public static DatePatternEnum format(String pattern){
        if(Strings.isNullOrEmpty(pattern)){
            return null;
        }
        for (DatePatternEnum value : DatePatternEnum.values()) {
            if(value.getPattern().equals(pattern)){
                return value;
            }
        }
        return null;
    }

    public String getPattern() {
        return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    public String getReg() {
        return reg;
    }

    public void setReg(String reg) {
        this.reg = reg;
    }
}
